Repository navigation
feat(app): add a duration heatmap view to trace search - #3184
alex-fedotyev wants to merge 7 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 8c2175f The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
| // (undefined -> id) doesn't count as a change and a shared link that pins | ||
| // ?traceChartMode=heatmap survives. | ||
| const prevSourceIdRef = useRef<string | undefined>(undefined); | ||
| useEffect(() => { |
There was a problem hiding this comment.
🔵 minor — Reset effect discards the user's Heatmap choice even when the new source can render it
The effect fires on any searchedSource?.id change, so switching from trace source A to trace source B — both with a durationExpression, so both render the toggle via traceRedMetricsSource — silently flips the view back to RED. The sibling view toggle analysisMode (:1067) is deliberately not reset on source change even though delta needs a trace source too; that branch just renders nothing (:2637). Drop the effect (both the switch and the chart are already hidden when traceRedMetricsSource == null, so a lingering ?traceChartMode=heatmap is inert), or gate the reset on the new source not supporting the heatmap.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Keeping a reset, but since 364e04c and 8c2175f it only runs for a source the user picks, not on every source id change. A lingering ?traceChartMode=heatmap isn't inert: coming back to a trace source would reopen the heatmap and switch live tail off again. Back/Forward keeps whatever mode the URL restores.
PR Review
5 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 5 minor 3 posted as inline comment(s) on the changed lines. 2 listed below. Findings outside the changed lines2 minor
Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical (P0/P1) issues found in the reviewer results available at synthesis time. The change is a self-contained, URL-backed view toggle. The strongest signal is a behavioral divergence between the live-tail guard condition and the actual chart-render gate, plus missing tests for the new source-reset logic. 🟡 P2 — recommended
🔵 P3 nitpicks (1)
Reviewers (5): correctness-set reviewers returned partial coverage; results incorporated from testing, maintainability, project-standards, agent-native, learnings-researcher. Coverage note: 7 of 12 dispatched reviewers (correctness, performance, api-contract, adversarial, previous-comments, kieran-typescript, julik-frontend-races) had not returned results when synthesis was forced, so the async-race, type-safety, query-performance, and prior-comment dimensions are not reflected below. Project-standards found no violations (changeset Testing gaps: No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
e19f185 to
f73ecf0
Compare
| // can't disable live tail for a search that shows the histogram. | ||
| const isHeatmapChartVisible = | ||
| analysisMode === 'results' && | ||
| traceRedMetricsSource != null && |
There was a problem hiding this comment.
🔵 minor — Switching back to RED leaves live tail off
The pin writes isLive=false into the URL, and nothing restores it. A user who looks at the heatmap for a moment and switches back to RED is left on a frozen time range with live tail off. Pausing live updates through useLiveUpdate's pause while the heatmap is visible, instead of overwriting isLive, would bring live tail back when the user switches to RED.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Intended: delta and pattern modes turn live tail off the same way, and pausing instead would leave the TimePicker and the results count claiming live tail over a frozen range. Back on RED, Resume Live Tail brings it back in one click.
ce233e9 to
46b3d9e
Compare
…3221) ## Summary Fixes the heatmap part of #3205: during a dashboard refresh, heatmap tiles now keep the current heatmap on screen and pulse, instead of replacing it with "Loading...". - Both heatmap queries (the min/max bounds and the buckets) keep their previous result as placeholder data, the same way the time chart and the number, bar and pie tiles do. - The bucket query waits for the refreshed bounds before it runs, so a refresh doesn't also query the new range bucketed with the previous range's min/max. - The heatmap, and the "Not enough data points" message, pulse while either query is still showing previous data. `Heatmap` takes an optional `className` so the pulse goes on its existing container rather than a new wrapper, which would affect its size measurement. - New tests in `DBHeatmapChart.render.test.tsx`: both queries keep their previous data, the tile pulses during a refresh and stops once fresh data loads, and the bucket query waits for fresh bounds. Three of the four fail without the change. While checking the rest of the app for the same pattern, I found two more places: the Kubernetes dashboard's Pods, Nodes and Namespaces tables still switch to skeleton rows on every refresh, and the Services dashboard tiles (`DBListBarChart`, `DBHistogramChart`, the slowest events tile) keep their data but don't pulse. Happy to take those as follow-ups if you'd like. ### How to test on Vercel preview **Preview routes:** /dashboards **Steps:** 1. Create a dashboard with a Heatmap tile on the demo traces source (for example on `Duration`) and a Line time chart. 2. Choose a large time range so each query takes a moment. 3. Click "Refresh dashboard". 4. Verify the heatmap stays on screen and pulses while its queries run, like the line chart, and stops pulsing once the new heatmap appears. ### References - Linear Issue: N/A - Related PRs: #3211, #3212. #3184 also edits the `queryKey` of these two heatmap queries, so whichever lands second needs a small rebase. - Closes part of #3205 Checks run locally: `jest` for the heatmap suites and `ChartPreviewPanel` (50 passed), `eslint` on changed files (0 errors, no new warnings), `prettier --check`, and `tsc --noEmit` for `packages/app`.
46b3d9e to
5809452
Compare
E2E Test Results✅ All tests passed • 467 passed • 1 skipped • 1003s
Tests ran across 4 shards in parallel. |
92739e6 to
d572b24
Compare
| ? histogramTimeChartConfig.groupBy.length > 0 | ||
| : false; | ||
|
|
||
| if (mode === 'heatmap') { |
There was a problem hiding this comment.
🔵 minor — The new heatmap branch of TraceRedMetricsChart has no test
Add a component test that renders mode="heatmap" and checks that DBHeatmapChart gets a distribution query whose value is getDurationMsExpression(source), uses HEATMAP_DURATION_NUMBER_FORMAT and log scale, and receives queryKeyPrefix. Today only the guard hook and useHeatmapData keys are tested, so a wrong expression or format here would still pass (there is no TraceRedMetricsChart test under components/Search/__tests__/).
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Not adding a component test here: the branch is checked on the preview (duration value, ms format, log scale), and e2e for the view, which covers it end to end, is tracked in #3176.
| // the search's chart config over the searched range, carrying the source's | ||
| // select-alias definitions. Memoized so the tile's query stays stable across | ||
| // re-renders. | ||
| const traceHeatmapChartConfig = useMemo( |
There was a problem hiding this comment.
🔵 minor — traceHeatmapChartConfig duplicates the delta heatmap's inline config
The delta-mode DBSearchHeatmapChart (DBSearchPage.tsx:2908-2912) builds the same {...chartConfig, dateRange: searchedTimeRange, with: aliasWith} object inline on every render. Pass the memoized traceHeatmapChartConfig there too (renamed to something like heatmapBaseChartConfig) so the base config has one source of truth.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
That would change the delta view's code path, which this PR otherwise leaves alone, so I'm keeping it out of this PR.
3f41fe6 to
7cae7bb
Compare
| ? histogramTimeChartConfig.groupBy.length > 0 | ||
| : false; | ||
|
|
||
| if (mode === 'heatmap') { |
There was a problem hiding this comment.
🔵 minor — TraceRedMetricsChart now renders two unrelated views behind a mode early return
In heatmap mode the component still computes the RED configs and receives props it doesn't use (onFocusSeries, throughputQueryKeyPrefix, histogram config). In RED mode it needs heatmapChartConfig, and DBSearchPage now gates the RED tiles on traceHeatmapChartConfig != null. This breaks the Single Responsibility convention. Fix: add a separate small TraceDurationHeatmapChart and pick between the two in DBSearchPage on traceChartMode. TraceRedMetricsChart then stays RED-only.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Keeping one component: both views take the same search config, source and ready state, and the page picks the view in one place. A second component would carry the same props without changing behavior.
| <SegmentedControl | ||
| size="xs" | ||
| value={traceChartMode} | ||
| onChange={v => |
There was a problem hiding this comment.
🔵 minor — Switch options are hand-written rather than derived from TRACE_CHART_MODES, and the ?? 'red' fallback never runs
TRACE_CHART_MODES says the view switch reads from it, but the data array lists 'red'/'heatmap' as literals. A new mode added to the list would parse from the URL but never appear in the switch. SegmentedControl only emits values from data, so the find(...) ?? 'red' fallback is dead code. Fix: build data from TRACE_CHART_MODES with a Record<TraceChartMode, string> label map, and narrow v with that list.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
The fallback narrows find's possibly-undefined result for the type. A new mode also needs its label in the switch, which sits next to the handler, so I left the two entries inline rather than add a label map.
Adds a RED/Heatmap switch to the trace results chart area. Heatmap renders the duration distribution over time as the same tile the dashboard does. The mode is URL state, so a reload or a shared link reopens the same view, and it resets to RED when the source changes. The heatmap's bounds and bucket queries take the search's RED query-key prefix (DBHeatmapChart gains the queryKeyPrefix prop DBTimeChart already has; keys are unchanged for callers that don't pass one), so live tail waits on them instead of stacking a fresh pair each tick. Live tail is also pinned off while the heatmap is the visible chart: a tick moves the absolute time range, and the heatmap keys its uPlot instance on the chart config, so each refresh would otherwise tear the chart down and rebuild it. The switch, the chart branch and the live-tail pin share one derived source, so the heatmap renders (and pins live tail) only where the RED tiles would: a trace source with a duration column, a non-compact viewport, and no custom group-by. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The live-tail pin only ran when the heatmap first appeared, so Resume Live Tail (or the TimePicker's Live option) turned live tail back on while the heatmap was still showing, and every tick rebuilt the chart. - Hide the TimePicker's Live option and the Resume Live Tail button while the heatmap is the visible chart, the way delta and pattern modes hide them, and make the guard check isLive so any other path that turns live tail on (a relative range pick) is switched off again. - Move the source-change reset and the live-tail guard into useTraceChartModeGuards, with tests for first load, a real source switch, and resuming live tail under the heatmap. - Drop the @source tag on the heatmap query in favor of a plain note, and document that queryKeyPrefix only applies to distribution heatmaps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nuqs 1.x writes an explicitly set default into the URL, so resetting the trace chart mode with 'red' added ?traceChartMode=red on every source switch, log sources included. Clear the param instead; the mode still falls back to RED. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mode union lived in TraceRedMetricsChart and a hand-written copy in the URL parser, so a mode added to the type alone would compile but parse back to RED. Export TRACE_CHART_MODES, derive TraceChartMode from it, and use it in the parser and the view switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The prefix let live tail wait on the heatmap queries, but live tail is always off while the heatmap is the visible chart, so it never changed anything. It did give these queries different keys from the identical delta-view heatmap. Without it, DBHeatmapChart and useHeatmapData go back to their current shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reset ran in an effect on the searched source id, so it also fired when Back or Forward restored a URL with traceChartMode=heatmap, and rewrote that history entry back to RED. Clear the mode in the page's existing user-source-change branch instead, which catch-up (history navigation, a source name resolving) already skips. The hook keeps only the live-tail guard, renamed useHeatmapLiveTailGuard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7cae7bb to
364e04c
Compare
| // off again). Cleared rather than set to 'red': nuqs 1.x writes an | ||
| // explicit default into the URL. Catch-up skips this branch, so | ||
| // Back/Forward keeps the mode the URL restores. | ||
| setTraceChartMode(null); |
There was a problem hiding this comment.
🔵 minor — The rule that resets traceChartMode on a source change has no test, and the PR description says it does
The reset moved inline into the source-change effect, and only the live-tail guard has tests now. The PR description still lists useTraceChartModeGuards reset tests and a DBHeatmapChart queryKeyPrefix with useHeatmapData tests, none of which are in this diff. Add DBSearchPage tests for three cases: a user-picked source clears traceChartMode, a catch-up from source name to ID keeps it, and a saved-search load keeps it. Update the description to match.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
The description is updated and no longer lists those tests or the prefix. The reset has no page-level unit test; I checked it on the preview (a picked source clears the mode, Back/Forward keeps it), and e2e for the view is tracked in #3176.
Clearing the mode from the dropdown branch ran before the debounced search submit pushed the new source, so it rewrote the previous history entry, and Back still landed on RED. Mark the reset as pending there, like the filter and group-by reconciles, and clear the mode once the URL points at the new source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| chartConfig == null | ||
| ? undefined | ||
| : ({ | ||
| ...chartConfig, |
There was a problem hiding this comment.
🔵 minor — Heatmap config keeps the results table's orderBy, so sorting a column rebuilds the heatmap
Add orderBy: undefined to traceHeatmapChartConfig, the way histogramTimeChartConfig and filtersChartConfig do. The heatmap's query keys already drop orderBy (buildHeatmapBoundsConfig/buildHeatmapBucketConfig in DBHeatmapChart/heatmapQueries.ts). But DistributionHeatmapChart sets plotKey={JSON.stringify(query.config)}, and that string still contains the search's orderBy. So clicking a sort header (onSortingChange → setSearchedConfig({orderBy})) changes chartConfig, which tears down and recreates the uPlot instance even though the data hasn't changed. That is the same rebuild this PR's live-tail guard comment is trying to avoid.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Right: sorting the results table changes the plotKey and remounts the heatmap. The fix is orderBy: undefined on traceHeatmapChartConfig, as histogramTimeChartConfig does. I'm leaving it to the reviewer's call on scope rather than another round here.
Stack
Layer 2 of 2 in a GitHub stack (stack #3688). GitHub shows this PR's base as
alex/red-metrics-trace-search-v2, the branch below it, but the stack's base ismain: merging this PR lands it and #3183 onmain, one squashed commit each. Its diff is only the heatmap layer, and CI runs as if it targetsmain:Summary
Adds a RED/Heatmap switch to the trace search results view. Heatmap replaces the three RED tiles with the duration distribution over time, as the same bare heatmap tile the dashboard renders (
DBHeatmapChartwith atoHeatmapQueryquery), without the significant-fields comparison panel.traceChartMode, like the other view toggles on this page, so a reload, a shared link, or Back/Forward reopens the same view. Picking a different source in the dropdown resets it to RED, so returning to a trace source after viewing another one doesn't silently reopen in Heatmap and switch live tail off again. The reset waits until the URL points at the new source, like the page's filter and group-by reconciles, so it lands on the new history entry, and it clears the param rather than writingredinto every URL.getDurationMsExpression(the source's duration scaled to ms by itsdurationPrecision) with the existingHEATMAP_DURATION_NUMBER_FORMAT, the same pairing the delta-view heatmap uses. Value, count and scale are fixed rather than read from that view's settings drawer, so this stays a plain duration heatmap independent of the delta view's query state.DBHeatmapChartis used as is. The heatmap needs no query namespace of its own: live tail is off whenever it shows, so no tick can stack its queries.useHeatmapLiveTailGuard.?traceChartMode=heatmapcan't disable live tail on a search that shows the histogram.Screenshots
Light theme:
Dark theme:
Test plan
useHeatmapLiveTailGuardtests cover the guard: off when the heatmap appears, off again when resumed under it, untouched on RED.tsc --noEmit,eslintwith no new warnings, knip, and thetraceRedMetrics,DBTimeChartandDBSearchPagesuites green against currentmain.traceChartMode, coming back to traces resets to RED, and Back from Logs returns to the heatmap (as do Forward and Back after it); a custom group-by and a compact (390px) viewport fall back to the histogram with the switch hidden. The heatmap shows Loading while its queries are in flight and "Not enough data points" for a WHERE that matches nothing, and a failed search query hides the chart area and shows the query error.Notes
minorchangeset.mainindependently in refactor: Decompose heatmap query and view builders #3276 (HEATMAP_DURATION_NUMBER_FORMAT), which this uses.